package com.zl.controller;

import com.zl.entity.po.Stu;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author zhanglei2
 * @since 2019/12/11 9:40
 */
@Controller
public class LoginController {
    @RequestMapping("/login")
    public String login(Model model){
        model.addAttribute("msg","呵呵哈哈哈");
        return "index";
    }
    @RequestMapping("/user/login")
    public String userLogin(@RequestParam("username") String username, @RequestParam("password") String password, Model model, HttpServletRequest request){
    //    获取参数,返回到页面
        if(!StringUtils.isEmpty(username) && "123".equals(password)){
            Stu stu = new Stu(username,password);
            HttpSession session = request.getSession();
            session.setAttribute("user",stu);
            return "redirect:/main.html";
        }
        model.addAttribute("msg","用户名或者密码不正确!");
        return "index";
    }

}
